/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Header for of USB Panic Button "driver" 
 * \author Matthieu Myrsky <matthieu.myrsky@tkk.fi>
 */
#ifndef USB_PANIC_BUTTON
#define USB_PANIC_BUTTON
#include "USB_Linux.hpp"
#include "thread.hpp"
class CUSBPanicButtonCallback{
public:
  CUSBPanicButtonCallback(){}
  virtual ~CUSBPanicButtonCallback(){}
  
  
  virtual void OnUSBPanicButtonPressed() = 0;


};
#define REQUEST_TYPE   0x00a1
#define REQUEST_VALUE  0x0300
#define REQUEST_TO     0x01f4
#define VENDORID       0x1130
#define PRODUCTID      0x0202
class CUSBPanicButton: private gim::CThread
{
public:
  CUSBPanicButton();

  ~CUSBPanicButton();

  bool Open();

  bool Close();
  /** Assigns the USB Panic Button callback function. 
   *
   * This sets a function object for calling a USB Panic button
   * callback. If this is set, the interface calls the assigned
   * functions immediately when event is available.
   * 
   * \note As the function is run in the context of the receiving
   * thread, user must make sure that the callback function is
   * fast. As if the function executes too long, receiving events
   * is interrupted.
   *
   * @param[in] aCallback Pointer to class implementing the interface
   *                      CUSBPanicButtonCallback.
   */
  void SetUSBPanicButtonCallback(CUSBPanicButtonCallback *aCallback) {
        iCallback = aCallback;
  }


private:
  int ThreadFunction(const int aThreadNumber);
  bool iRunning;
  CUSB_Linux iUsb;
  CUSBPanicButtonCallback *iCallback;


  CUSBPanicButton(const CUSBPanicButton &) :
    CThread(1),
    iRunning(false),
    iUsb(),
    iCallback(NULL){}

  CUSBPanicButton& operator=(const CUSBPanicButton &) { return *this; }


};


#endif
